<!DOCTYPE html>
<html lang="zh-cmn-Hans">
<head>
    <meta charset="UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>登录</title>
    <link rel="stylesheet" href="frame/layui/css/layui.css">
    <link rel="stylesheet" href="frame/static/css/style.css">
    <link rel="icon" href="frame/static/image/code.png">
</head>
<body>
<div class="login-main">
    <header class="layui-elip">登入</header>
    <form class="layui-form">
        <div class="layui-input-inline">
            <input type="text" name="username" required lay-verify="required" id="username" placeholder="用户名" autocomplete="off"
                   class="layui-input">
        </div>
        <div class="layui-input-inline">
            <input type="password" name="password" required lay-verify="required" id="password" placeholder="密码" autocomplete="off"
                   class="layui-input">
        </div>
        <div class="layui-input-inline login-btn">
            <button type="button" class="layui-btn" onclick='loginByPwd()'>登录</button>
        </div>
        <hr/>
    </form>
</div>
<script src="frame/layui/layui.js"></script>
<script type="text/javascript" src="js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="js/md5.js"></script>
<script type="text/javascript">
    layui.use(['form'], function () {
        // 操作对象
        var form = layui.form
                , $ = layui.jquery;
    });
    $(document).keyup(function (e) {//捕获文档对象的按键弹起事件
	    if (e.keyCode == 13) {//按键信息对象以参数的形式传递进来了
	    	loginByPwd();
	    }
	});
	function loginByPwd(){
		var username = $('#username').val();
		var password = $('#password').val();
		if(username ==null||username=='') return;
		if(password ==null||password=='') return;
		$.ajax({
            type : "post",  //提交方式  
            url : "/api/user/login",//路径  
            async:false,
            data : {
            	'username':username,
            	'password':password
            },//数据，这里使用的是Json格式进行传输  
            dataType:'json',    //返回的数据格式：json/xml/html/script/jsonp/text
            success : function(result) {//返回数据根据结果进行相应的处理  
            	layer.msg(result.msg);
            	if(result.code==0){
            		window.location.href='/index.html';
            		window.event.returnValue=false; 
            		return;
            	}
            },
            error:function(XMLHttpRequest, textStatus, errorThrown){
            	layer.msg('系统异常');
            }
        }); 
	}
</script>
</body>
</html>